#!/usr/bin/python
# -*- coding:utf-8 -*-
def select_check(a):
    """检查查询语句语法
    1.select开头
    2.有from
    3.查询的表是否存在（yuangongbiao）
    5.查询的关键字是否含有非法字符
    6.检查where子句
    4.有返回值"""
    list = []
    for i in range(48, 57):
        list.append(chr(i))
    for i in range(65, 91):
        list.append(chr(i))
    for i in range(97, 123):
        list.append(chr(i))
    list.append(',')
    list.append('*')
    list.append('>')
    list.append('<')
    yufa_state = True
    if a[0:6] == 'select' and 'from' in a and a.count('select')==1 and a.count('from')==1:
        #判断关键字字母是不是以逗号分割
        guanjianzi = a[6:].split('from')

        guanjianzi = guanjianzi[0].strip()
        #只包含*，字母数字

        # print(list)
        for i in guanjianzi:
            if i in list:
        #判断有没有特殊符号
                pass#关键字只有一条
            else:
                print("输入了非法字符！")
                yufa_state = False
                break



    else:
        print('语法错误！')
        yufa_state =False
    #判断表名
    if 'yuangongbiao' in a :
        # print('查询的是员工表')
        pass
    else:
        print("查询的表不存在！")
        yufa_state =False
    if 'where' in a :#假设只有一个where
        temp = a.split('where')
        temp[1]=temp[1].strip()

    return yufa_state#返回语法正确与否


def select_split_cent(a):
    """对查询语句进行分割，找出关键字"""
    temp = a[6:].split('from')#去除语句中select并且通过from分割
    select_list = temp[0].strip().split(',')#查询的内容
    print('关键字',select_list)

    #判断有没有where子句
    if 'where' in temp[1]:
        where_exist_list = temp[1].strip()
        where_exist_list = temp[1][19:].strip().split('and')
        print(where_exist_list)
        #
    else:
        return select_list

def select_table(*kwargs):
    """查询员工信息表"""
while True:
    do_state = input('1-查询      2-添加新员工     3-删除员工记录    4-修改员工信息\n请选择您的操作：')
    if do_state =='1':
        select = True#检查语法错误
        while select:
            cent = input('请输入查询语句:').lower()
            #检查语法
            if select_check(cent) == True:#语法正确
                select_split_cent(cent)
                select=False
                #分割关键字
            else:
                pass

            #传参数，查询
                # break
    elif do_state =='2':
        pass
    elif do_state =='3':
        pass
    elif do_state =='4':
        pass
    else:
        print('您的选择有误，请重新选择！')